package com.cooper.base.vo;

import com.cooper.common.util.DateUtils;

public class SpMyShiroResultBuilder {

    private static final int OK = 200;
    private static final int ERROR = 500;
    private static final int SUCCEED = 1;
    private static final int FAILED = 0;

    private static SpMyShiroResultBuilder instance;

    private SpMyShiroResultBuilder() {
    }

    public static SpMyShiroResultBuilder getInstance() {
        if (instance == null) {
            instance = new SpMyShiroResultBuilder();
        }
        return instance;
    }

    public SpMyShiroResult success() {
        SpMyShiroResult spMyShiroResult = new SpMyShiroResult();
        spMyShiroResult.setCode(OK);
        spMyShiroResult.setTimestamp(DateUtils.strCurrentTimeInMilliseconds());
        spMyShiroResult.setStatus(SUCCEED);
        return spMyShiroResult;
    }

    public SpMyShiroResult success(String message) {
        SpMyShiroResult spMyShiroResult = new SpMyShiroResult();
        spMyShiroResult.setCode(OK);
        spMyShiroResult.setTimestamp(DateUtils.strCurrentTimeInMilliseconds());
        spMyShiroResult.setStatus(SUCCEED);
        spMyShiroResult.setMessage(message);
        spMyShiroResult.setData(null);
        return spMyShiroResult;
    }

    public SpMyShiroResult success(String message, Object data) {
        SpMyShiroResult spMyShiroResult = new SpMyShiroResult();
        spMyShiroResult.setCode(OK);
        spMyShiroResult.setTimestamp(DateUtils.strCurrentTimeInMilliseconds());
        spMyShiroResult.setStatus(SUCCEED);
        spMyShiroResult.setMessage(message);
        spMyShiroResult.setData(data);
        return spMyShiroResult;
    }

    public SpMyShiroResult fail(String message) {
        SpMyShiroResult spMyShiroResult = new SpMyShiroResult();
        spMyShiroResult.setCode(ERROR);
        spMyShiroResult.setTimestamp(DateUtils.strCurrentTimeInMilliseconds());
        spMyShiroResult.setStatus(FAILED);
        spMyShiroResult.setMessage(message);
        return spMyShiroResult;
    }
}
